package com.java.exer9;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Student2 implements Comparable {
    private String name;
    private int age;
    private boolean gender;
    private String stuNO;

    private static int count = 0;
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy");

    public Student2(String name, int age, boolean gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.stuNO = "stu" + sdf.format(new Date()) + "09" + String.format("%03d", ++count);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean isGender() {
        return gender;
    }

    public void setGender(boolean gender) {
        this.gender = gender;
    }

    public String getStuNO() {
        return stuNO;
    }

    public void setStuNO(String stuNO) {
        this.stuNO = stuNO;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", gender=" + (gender ? "男" : "女") +
                ", stuNO='" + stuNO + '\'' +
                '}';
    }

    @Override
    public int compareTo(Object o) {
        //nulls last
        if (o == null) {
            return -1;
        }
        //检测是否同类型
        if (!(o instanceof Student2)) {
            return -1;
        }

        Student2 st = (Student2) o;

        if (this.getAge() > st.getAge()) {
            return 1;
        } else if (this.getAge() == st.getAge()) {
            return 0;
        }


//		return this.getName().compareTo(st.getName());
        return -1;
    }
}
